package com.itheima.edu.info.manager.dao;

import com.itheima.edu.info.manager.domain.Teacher;

public class TeacherDao implements BaseTeacherDao{
    static Teacher[] teachers = new Teacher[5];
    public boolean addTeacher(Teacher teacher) {
        int index = -1;
        for (int i = 0; i < teachers.length; i++) {
            if (teachers[i] == null){
                index = i;
                break;
            }
        }
        if (index == -1){
            return false;
        }else {
            teachers[index] = teacher;
            return true;
        }
    }

    public Teacher[] findAllTeacher() {
        return teachers;
    }

    public void deleteTeacher(String tid) {
        for (int i = 0; i < teachers.length; i++) {
            if (teachers[i] != null && tid.equals(teachers[i].getId())){
                teachers[i] = null;
            }
        }
    }

    public void updateTeacher(Teacher teacher) {
        for (int i = 0; i < teachers.length; i++) {
            if (teachers[i] != null && teacher.getId().equals(teachers[i].getId())){
                teachers[i] = teacher;
            }
        }
    }
}
